const path = require('path')
const { CleanWebpackPlugin } = require("clean-webpack-plugin")
const htmlWebpackPlugin = require("html-webpack-plugin")
const webpack = require("webpack")
const { DefinePlugin } = webpack
const CopyPlugin = require("copy-webpack-plugin")
module.exports = {
    entry: "./src/index.js",
    mode: "development",
    devtool: "source-map",
    // watch:true,
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js',
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    { loader: "style-loader" },
                    {
                        loader: "css-loader",
                        "options": {
                            importLoaders: 1
                        }
                    },
                    { loader: 'postcss-loader' },
                ]
            },
            {
                test: /\.less$/,
                use: [
                    { loader: "style-loader" },
                    { loader: "css-loader", options: { importLoaders: 2 } },
                    { loader: 'postcss-loader' },
                    { loader: "less-loader" }
                ]
            },
            {
                test: /\.js$/g,
                exclude: /(node_modules|bower_components)/,
                loader: "babel-loader",
            },
            {
                test: /\.(jpe?g|png|gif|svg)$/i,
                type: 'asset',
                parser: {
                    dataUrlCondition: {
                        maxSize: 1024 * 10
                    }
                },
                generator: {
                    filename: "img/[name].[hash:6][ext]"
                }
            },
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new htmlWebpackPlugin({
            title: "你好啊",
            template: "./public/index.html",
            filename: "index.html"
        }),
        new DefinePlugin({
            "app": "'sss'"
        }),
        // new copyHtmlPlugin({
        //     "patterns": [
        //         {
        //             from: 'public',
        //             globOptions: {
        //                 ignore: [
        //                     "**/index.html",
        //                     "**/abc.txt",
        //                     "**/bbb.txt",
        //                     "**/*.txt"
        //                 ]
        //             }
        //         }
        //     ]
        // })
        new CopyPlugin({
            patterns: [
                {
                    from: "public",
                    "globOptions": {
                        "ignore": [
                            "**/index.html"
                        ]
                    }
                }
            ]
        })
    ]
}